<!-- <template>
    <div>
        <h2 style="text-align: center;">登录页面</h2>
        <table>
            <tr>
                <td>登录名称:</td>
                <td>
                    <input type="text" v-model="info.Uname" placeholder="请输入登录名称" />
                </td>
            </tr>

            <tr>
                <td>登录密码:</td>
                <td>
                    <input type="password" v-model="info.Upwd" placeholder="请输入登录密码" />
                </td>
            </tr>

            <tr>
                <td colspan="2" style="text-align: center;">
                    <input type="button" value="登录" class="btn btn-success" @click="LoginInfo">
                </td>
            </tr>
        </table>
    </div>
</template>-->

<template>
<div>
    <link rel="stylesheet" href="./src/assets/DomCss/css/login.css">
<!-- BEGIN LOGIN -->
<div class="pure-g content">
	<div class="pure-form pure-u-1">
        <h4>登录页面</h4>
        <fieldset class="pure-group">
            <input type="text" class="pure-input-1" placeholder="用户名" v-model="info.Uname" required autofocus >
            <input type="password" class="pure-input-1" placeholder="密　码" v-model="info.Upwd" required>
        </fieldset>
        <button class="pure-button pure-u-1 pure-button-primary" type="button" @click="LoginInfo">登　录</button>
	</div>
</div>
<!-- END LOGIN -->
<!--BEGIN FOOT-->
<div class="pure-g copyright">
    <div class="pure-u-1"> 2024 © ZJY. </div>
</div>

</div>
</template>
<script setup lang="ts">
import {ref} from 'vue'
import axios from 'axios';
import router from '../../router';
import {useUserStore} from '../../store/index.ts'

//创建仓库实例
const userStore=useUserStore();

//创建响应式数据
const info=ref({
    Uname:"",
    Upwd:""
})

//完成用户登录
const LoginInfo=()=>{
    axios.get("https://localhost:44321/api/Users/UserLoginInfo",
        {
            params:{
                Uname:info.value.Uname,
                Upwd:info.value.Upwd
            }
        }
    )
    .then(res=>{
        if(res.data.T_Code==0)
        {
            alert(res.data.T_Msg);
        }
        else if(res.data.T_Code==1)
        {
            alert(res.data.T_Msg);
        }
        else if(res.data.T_Code==3)
        {
            alert(res.data.T_Msg);
            //将用户编号保存到仓库中
            userStore.Uid=res.data.T_Info[0].U_Id;
            SearchUid(res.data.T_Info[0].U_Id);
            
            
        }
        else
        {
            alert('登录失败');
        }
    })
    .catch(error=>{
        console.log(error);
    })
}

//检查用户之前是否完善过个人信息
const SearchUid=(Uid:string)=>{
    axios.get("https://localhost:44321/api/Users/SearchUid",
        {
            params:{
                Uid:Uid
            }
        }
    )
    .then(res=>{
        console.log(res.data);
        if(res.data>0)
        {
            //说明用户已经完善过个人信息,即将跳转到主页面
            router.push({
                name:"Home",
                params:{
                    Uid:Uid
                }
            })
        }
        else
        {
            //没有完善过个人信息 则跳转到用户详情页面
            //跳转用户详情页面
            router.push({
                name:"RegisterInfo",
                params:{
                    Uid:Uid
                }
            })
        }
    })
    .catch(error=>{
        console.log(error);
    })
}
</script>
